package com.leoman.controller.api;

import com.leoman.core.bean.Result;
import com.leoman.entity.Circle;
import com.leoman.entity.Placard;
import com.leoman.service.CircleService;
import com.leoman.service.PlacardService;
import com.leoman.utils.JsonUtil;
import com.leoman.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 黑板api
 * Created by 涂奕恒 on 2016/11/25 0018.
 */
@Controller
@RequestMapping(value = "api/placard")
public class PlacardApi {

    @Autowired
    private PlacardService placardService;

    /**
     * @api {post} /api/placard/list 1、黑板公告列表
     * @apiVersion 0.0.1
     * @apiName placard.list
     * @apiGroup placard
     *
     * @apiDescription 黑板公告列表
     *
     * @apiParam   {Integer}   userId                     用户Id
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    草丛ID
     * @apiSuccess {Integer}   list.title                 标题
     * @apiSuccess {String}    list.cover                 封面图url
     * @apiSuccess {String}    list.content               内容
     * @apiSuccess {String}    list.synopsis              简介
     * @apiSuccess {Integer}   list.isTop                 是否置顶，0=否，1=是
     * @apiSuccess {Integer}   list.praiseNum             点赞数
     * @apiSuccess {Integer}   list.commentNum            评论数
     * @apiSuccess {Integer}   list.isPraise              是否点赞，0=否，1=是
     * @apiSuccess {String}    list.createTime            发送时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "title" : 1,
     *                  "cover" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "content" : "我是一只萌萌哒小兔子，我生长在美丽的帕斯米尔大草原，我从小就喜欢吃青草",
     *                  "synopsis" : "我是一只萌萌哒小兔子，我生长在美丽的帕斯米尔大草原，我从小就喜欢吃青草",
     *                  "isTop" : 1,
     *                  "praiseNum" : 124,
     *                  "commentNum" : 20,
     *                  "isPraise" : 0,
     *                  "createTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public void list(HttpServletResponse response, Integer userId, Integer pageNum, Integer pageSize) {
        Page<Placard> page = placardService.iPageForApp(userId, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "user");
        WebUtil.printApi(response, result);
    }
}
